# To change this template, choose Tools | Templates
# and open the template in the editor.




from hexconfig import *
import pygame

class nodeDictionary():
    def __init__(self):
        self.p0Keys = {}
        self.totalNodes = 0

    def keys(self):
        returnList = []
        for p0Key in self.p0Keys.keys():
            for fullKey in self.p0Keys[p0Key].keys():
                returnList.append(decompressStateRLE(fullKey))
        return returnList

    def getP0Keys(self):
        return [decompressStateRLE(key)for key in self.p0Keys.keys()]
    def getP0KeyList(self, stateString):
        retlist = []
        p0KeyString = compressStateRLE(getP0KeyString(stateString))
        try:
            for key in self.p0Keys[p0KeyString].keys():
                retlist.append(self.p0Keys[p0KeyString][key])

            try:
                self.p0Keys[p0KeyString][compressStateRLE(key)]
            except KeyError:
                print "node", stateString, "is not in the nodeDictionary FYI"

            return retlist

        except KeyError:
            print "nodeGroup", stateString, "doesn't exist"
            return []


    def __getitem__(self, key):
        try:
            return self.p0Keys[compressStateRLE(getP0KeyString(key))][compressStateRLE(key)]
        except KeyError:
            #print "KEYERR-",key
            raise KeyError

    def __contains__(self, key):
        try:
            self.p0Keys[compressStateRLE(getP0KeyString(item))][compressStateRLE(item)]
            return True
        except KeyError:
            return False

    def __setitem__(self,key,value):
        p0KeyString = compressStateRLE(getP0KeyString(key))
        compKey = compressStateRLE(key)


        #print "KEY",key

        #print "CompKey",compKey

        try:
            p0KeyDict = self.p0Keys[p0KeyString]
        except KeyError:
            self.p0Keys[p0KeyString] = {}
            p0KeyDict = self.p0Keys[p0KeyString]

        try:
            p0KeyDict[compKey]
        except KeyError:
            self.totalNodes += 1

        p0KeyDict[compKey] = value
        #print "BLAH BLAH BLAH",p0KeyDict[compKey]

    def __delitem__(self,key):
        key = compressStateRLE(key)
        try:
            del self.p0Keys[getP0KeyString(key)][key]
            self.totalNodes -= 1
        except KeyError:
            raise KeyError

    def __len__(self):

        return self.totalNodes




if __name__ == "__main__":
    nd = nodeDictionary() #self.nodes
    stateStrings = ["-","A","B","1","0","1"]
    for s in stateStrings:
        nd[s] = StateNode(s) #self.nodes[s] = StateNode(s)

        #print s

    print nd.keys()
    for key in nd.keys():
        print nd[key]
    print len(nd)
    del nd["A"]
    for key in nd.keys():
        print nd[key]
    print len(nd)

